/*
* jlb
*/
package com.jlb.user.ctrl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jlb.active.entity.ActiveRecord;
import com.jlb.active.service.ActivePoolSV;
import com.jlb.active.service.ActiveRecordSV;
import com.jlb.base.ctrl.AppBaseCtrl;
import com.jlb.core.entity.BeanRet;
import com.jlb.core.entity.Page;
import com.jlb.core.enums.YNEnum;
import com.jlb.core.tools.redis.RedisUtils;
import com.jlb.core.tools.security.Md5;
import com.jlb.jlb.entity.JlbOreLog;
import com.jlb.jlb.entity.TransferType;
import com.jlb.jlb.service.JlbOreLogSV;
import com.jlb.my.service.MyGroupSV;
import com.jlb.ore.entity.OreRecord;
import com.jlb.ore.service.OreRecordSV;
import com.jlb.user.entity.*;
import com.jlb.user.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 用户 控制器
 *
 * @author jlb
 */
@RestController
@RequestMapping("/app/user")
@Slf4j
@Api(value = "用户控制器", description = "用户端：用户控制器")
public class AppUserCtrl extends AppBaseCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private UserSV userSV;

    @Resource
    private UserSubAccountSV subAccountSV;

    @Resource
    private UserBankCardSV userBankCardSV;

    //注入用户金兰宝业务
    @Resource
    private UserJlbSV userJlbSV;

    @Resource
    private UserMinerSV userMinerSV;

    @Resource
    private UserGroupSV userGroupSV;

    @Resource
    private MyGroupSV myGroupSV;

    //注入用户矿石业务
    @Resource
    private UserOreSV userOreSV;

    //注入激活币业务
    @Resource
    private ActivePoolSV activePoolSV;

    //注入用户押金业务
    @Resource
    private UserDepositSV userDepositSV;

    //注入我的激活币业务
    @Resource
    private UserActiveSV userActiveSV;

    //注入转账记录业务
    @Resource
    private JlbOreLogSV jlbOreLogSV;

    //注入矿石业务
    @Resource
    private OreRecordSV oreRecordSV;

    //注入矿机挖金兰宝记录
    @Resource
    private UserMinerWorkRecordSV userMinerWorkRecordSV;

    @Resource
    private ActiveRecordSV activeRecordSV;


    /**
     * 我的个人信息及各种余额信息
     *
     * @return BeanRet
     */
    @ApiOperation(value = "我的个人信息及各种余额信息", notes = "我的个人信息及各种余额信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(@ApiIgnore HttpServletRequest request) {
        String userCode = this.getUserCode(request);
        User user = userSV.loadByCode(userCode);
        log.info(JSON.toJSONString(user));
        return BeanRet.create(true, "查询成功", user);
    }


    /**
     * 我的直推人数
     *
     * @return BeanRet
     */
    @ApiOperation(value = "我的直推人数", notes = "我的直推人数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @GetMapping(value = "/getMyInvite")
    @ResponseBody
    public BeanRet getMyInvite(@ApiIgnore HttpServletRequest request) {
        String userCode = this.getUserCode(request);
        Map<String, Object> params = new HashedMap();
        params.put("preUserCode", userCode);
        Integer invite = userGroupSV.count(params);
        return BeanRet.create(true, "查询成功", invite);
    }


    /**
     * 我的押金
     *
     * @return BeanRet
     */
    @ApiOperation(value = "我的押金", notes = "我的押金")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @GetMapping(value = "/getMyDeposit")
    @ResponseBody
    public BeanRet getMyDeposit(@ApiIgnore HttpServletRequest request) {
        String userCode = this.getUserCode(request);
        Integer deposit = userDepositSV.sumDeposit(userCode, UserDepositState.Frozen.name());
        return BeanRet.create(true, "查询成功", deposit != null ? deposit : 0);
    }

    /**
     * 我的激活币
     *
     * @return BeanRet
     */
    @ApiOperation(value = "我的激活币", notes = "我的激活币")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @GetMapping(value = "/getMyActive")
    @ResponseBody
    public BeanRet getMyActive(@ApiIgnore HttpServletRequest request) {
        String userCode = this.getUserCode(request);
        Map<String, Object> params = new HashedMap();
        params.put("userCode", userCode);
        Integer myActive = userActiveSV.count(params);
        return BeanRet.create(true, "查询成功", myActive != null ? myActive : 0);
    }


    /**
     * 设置/修改身份证号
     */
    @ApiOperation(value = "设置/修改身份证号", notes = "设置/修改身份证号")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "idCard", value = "身份证号", paramType = "query", required = true),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @PutMapping(value = "/updateIdCard")
    @ResponseBody
    public BeanRet updateIdCard(@ApiIgnore HttpServletRequest request, String idCard) {
        if (StringUtils.isEmpty(idCard)) {
            return BeanRet.create(false, "参数为空");
        }
        String userCode = this.getUserCode(request);
        userSV.updateIdCard(userCode, idCard);
        return BeanRet.create(true, "身份证设置成功");
    }

    /**
     * 设置/修改支付宝
     */
    @ApiOperation(value = "设置/修改支付宝", notes = "设置/修改支付宝")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "alipay", value = "支付宝号", paramType = "query", required = true),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @PutMapping(value = "/updateAlipay")
    @ResponseBody
    public BeanRet updateAlipay(@ApiIgnore HttpServletRequest request, String alipay) {
        if (StringUtils.isEmpty(alipay)) {
            return BeanRet.create(false, "参数为空");
        }
        String userCode = this.getUserCode(request);
        userSV.updateAlipay(userCode, alipay);
        return BeanRet.create(true, "支付宝设置成功");
    }

    /**
     * 设置/修改真实名称
     */
    @ApiOperation(value = "设置/修改真实名称", notes = "设置/修改真实名称")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "realName", value = "真实姓名", paramType = "query", required = true),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @PutMapping(value = "/updateRealName")
    @ResponseBody
    public BeanRet updateRealName(@ApiIgnore HttpServletRequest request, String realName) {
        if (StringUtils.isEmpty(realName)) {
            return BeanRet.create(false, "参数为空");
        }
        String userCode = this.getUserCode(request);
        userSV.updateRealName(userCode, realName);
        return BeanRet.create(true, "姓名修改成功");
    }

    /**
     * 设置/修改手机号
     */
    @ApiOperation(value = "设置/修改手机号", notes = "设置/修改手机号")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "手机号", paramType = "query", required = true),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @PutMapping(value = "/updatePhone")
    @ResponseBody
    public BeanRet updatePhone(@ApiIgnore HttpServletRequest request, String phone) {
        if (StringUtils.isEmpty(phone)) {
            return BeanRet.create(false, "参数为空");
        }
        String userCode = this.getUserCode(request);
        userSV.updatePhone(userCode, phone);
        return BeanRet.create(true, "手机号修改成功");
    }

    /**
     * 设置/修改微信
     */
    @ApiOperation(value = "设置/修改微信", notes = "设置/修改微信")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wechat", value = "微信号", paramType = "query", required = true),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @PutMapping(value = "/updateWechat")
    @ResponseBody
    public BeanRet updateWechat(@ApiIgnore HttpServletRequest request, String wechat) {
        if (StringUtils.isEmpty(wechat)) {
            return BeanRet.create(false, "参数为空");
        }
        String userCode = this.getUserCode(request);
        userSV.updateWechat(userCode, wechat);
        return BeanRet.create(true, "微信设置成功");
    }

    /**
     * 修改用户昵称
     */
    @ApiOperation(value = "修改用户昵称", notes = "修改用户昵称")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "nickName", value = "昵称", paramType = "query", required = true),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @PutMapping(value = "/updateNickName")
    @ResponseBody
    public BeanRet updateNickName(@ApiIgnore HttpServletRequest request, String nickName) {
        if (StringUtils.isEmpty(nickName)) {
            return BeanRet.create(false, "参数为空");
        }
        String userCode = this.getUserCode(request);
        userSV.updateNickName(userCode, nickName);
        return BeanRet.create(true, "昵称设置成功");
    }

    /**
     * 修改登录密码
     */
    @ApiOperation(value = "修改登录密码", notes = "修改登录密码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "password", value = "登录密码", paramType = "query", required = true),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @PutMapping(value = "/updatePassword")
    @ResponseBody
    public BeanRet updatePassword(@ApiIgnore HttpServletRequest request, String password) {
        if (StringUtils.isEmpty(password)) {
            return BeanRet.create(false, "参数为空");
        }
        String userCode = this.getUserCode(request);
        userSV.updatePassword(userCode, password);
        return BeanRet.create(true, "登录密码修改成功");
    }

    /**
     * 修改交易密码
     */
    @ApiOperation(value = "修改交易密码", notes = "修改交易密码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pinPassword", value = "交易密码", paramType = "query", required = true),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @PutMapping(value = "/updatePinPassword")
    @ResponseBody
    public BeanRet updatePinPassword(@ApiIgnore HttpServletRequest request, String pinPassword) {
        if (StringUtils.isEmpty(pinPassword)) {
            return BeanRet.create(false, "参数为空");
        }
        String userCode = this.getUserCode(request);
        userSV.updatePinPassword(userCode, pinPassword);
        return BeanRet.create(true, "交易密码修改成功");
    }

    /**
     * 用户间互转激活币
     */
    @ApiOperation(value = "用户间互转激活币", notes = "用户间互转激活币")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "接收者账户", paramType = "query", required = true),
            @ApiImplicitParam(name = "num", value = "要转的激活码数量", paramType = "query", required = true),
            @ApiImplicitParam(name = "pinPassword", value = "交易密码", paramType = "query"),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @PostMapping(value = "/transferActiveCode")
    @ResponseBody
    public BeanRet transferActiveCode(@ApiIgnore HttpServletRequest request, String account, Integer num, String pinPassword) {
        if (StringUtils.isEmpty(account) || num == null || StringUtils.isEmpty(pinPassword)) {
            return BeanRet.create(false, "参数为空");
        }
        if (num <= 0) {
            return BeanRet.create(false, "转账必须大于0");
        }
        String userCode = this.getUserCode(request);
        User user = userSV.loadByCode(userCode);
        activePoolSV.userTransfer(user, account, num, pinPassword);
        return BeanRet.create(true, "成功转账");
    }

    /**
     * 用户间互转金兰宝
     */
    @ApiOperation(value = "用户间互转金兰宝", notes = "用户间互转金兰宝")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "接收者账户", paramType = "query", required = true),
            @ApiImplicitParam(name = "num", value = "转赠数量", paramType = "query", required = true),
            @ApiImplicitParam(name = "pinPassword", value = "交易密码:如果是子账户转账，可以不用输交易密码", paramType = "query"),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @PostMapping(value = "/transferJlb")
    @ResponseBody
    public BeanRet transferJlb(@ApiIgnore HttpServletRequest request, String account, Integer num, String pinPassword) {
        if (StringUtils.isEmpty(account) || num == null || StringUtils.isEmpty(pinPassword)) {
            return BeanRet.create(false, "参数为空");
        }
        if (num <= 0) {
            return BeanRet.create(false, "转账必须大于0");
        }
        String userCode = this.getUserCode(request);
        User user = userSV.loadByCode(userCode);
        userJlbSV.transfer(user, account, num, pinPassword);
        return BeanRet.create(true, "成功转账");
    }

    /**
     * 用户间互转矿石
     */
    @ApiOperation(value = "用户间互转转矿石", notes = "用户间互转转矿石")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "接收者账户", paramType = "query", required = true),
            @ApiImplicitParam(name = "num", value = "转赠数量", paramType = "query", required = true),
            @ApiImplicitParam(name = "pinPassword", value = "交易密码:如果是子账户转账，可以不用输交易密码", paramType = "query"),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @PostMapping(value = "/transferOre")
    @ResponseBody
    public BeanRet transferOre(@ApiIgnore HttpServletRequest request, String account, Integer num, String pinPassword) {
        if (StringUtils.isEmpty(account) || num == null || StringUtils.isEmpty(pinPassword)) {
            return BeanRet.create(false, "参数为空");
        }
        if (num <= 0) {
            return BeanRet.create(false, "转账必须大于0");
        }
        String userCode = this.getUserCode(request);
        User user = userSV.loadByCode(userCode);
        userOreSV.transfer(user, account, num, pinPassword);
        return BeanRet.create(true, "成功转账");
    }

    /**
     * 用户间互转余额
     */
    @ApiOperation(value = "用户间互转余额", notes = "用户间互转余额:根据矿机选择，可以修改数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "接收者账户", paramType = "query", required = true),
            @ApiImplicitParam(name = "jlb", value = "金兰宝数量", paramType = "query", required = true),
            @ApiImplicitParam(name = "ore", value = "矿石数量", paramType = "query"),
            @ApiImplicitParam(name = "active", value = "激活币数量", paramType = "query"),
            @ApiImplicitParam(name = "pinPassword", value = "交易密码", paramType = "query", required = true),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @PostMapping(value = "/transfer")
    @ResponseBody
    public BeanRet transfer(@ApiIgnore HttpServletRequest request, String account, Integer jlb, Integer ore, Integer active, String pinPassword) {
        if (StringUtils.isEmpty(account) || jlb == null || StringUtils.isEmpty(pinPassword)) {
            return BeanRet.create(false, "参数为空");
        }

        String userCode = this.getUserCode(request);
        User user = userSV.loadByCode(userCode);

        //转金兰宝
        if (jlb < 0) {
            return BeanRet.create(false, "金兰宝的数量不能小于0");
        }
        if (ore < 0) {
            return BeanRet.create(false, "矿石的数量不能小于0");

        }
        if (active < 0) {
            return BeanRet.create(false, "激活币的数量不能小于0");
        }

        userJlbSV.transfer(user, account, jlb, pinPassword);


        //转矿石
        if (ore != null && ore > 0) {
            userOreSV.transfer(user, account, ore, pinPassword);
        }
        //转激活币
        if (active != null && active > 0) {
            activePoolSV.userTransfer(user, account, active, pinPassword);
        }
        return BeanRet.create(true, "成功转账");
    }

    /**
     * 用户子账户转账
     */
    @ApiOperation(value = "用户子账户转账", notes = "用户子账户转账")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "subAccount", value = "子账户", paramType = "query", required = true),
            @ApiImplicitParam(name = "account", value = "接收者账户", paramType = "query", required = true),
            @ApiImplicitParam(name = "jlb", value = "金兰宝数量", paramType = "query", required = true),
            @ApiImplicitParam(name = "pinPassword", value = "交易密码", paramType = "query", required = true),
            @ApiImplicitParam(name = "ore", value = "矿石数量", paramType = "query"),
            @ApiImplicitParam(name = "active", value = "激活币数量", paramType = "query"),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @PostMapping(value = "/transferSubAccount")
    @ResponseBody
    public BeanRet transferSubAccount(@ApiIgnore HttpServletRequest request, String subAccount, String account, Integer jlb, Integer ore, Integer active, String pinPassword) {
        if (StringUtils.isEmpty(subAccount) || StringUtils.isEmpty(account) || StringUtils.isEmpty(pinPassword)) {
            return BeanRet.create(false, "参数为空");
        }
        if (jlb == null && ore == null && active == null) {
            return BeanRet.create(false, "转账金额不能为空");
        }
        //转金兰宝
        if (jlb != null && jlb < 0) {
            return BeanRet.create(false, "金兰宝的数量不能小于0");
        }
        if (ore != null && ore < 0) {
            return BeanRet.create(false, "矿石的数量不能小于0");

        }
        if (active != null && active < 0) {
            return BeanRet.create(false, "激活币的数量不能小于0");
        }

        String userCode = this.getUserCode(request);
        User fatherUser = userSV.loadByCode(userCode);
        if (!Md5.md5(pinPassword).equals(fatherUser.getPinPassword())) {
            return BeanRet.create(false, "交易密码不正确");
        }

        //转金兰宝
        User user = userSV.loadByAccount(subAccount);
        user.setPinPassword(fatherUser.getPinPassword());
        if (user == null) {
            return BeanRet.create(false, "转出账户不存在");
        }
        if (jlb != null && jlb > 0) {
            userJlbSV.transfer(user, account, jlb, pinPassword);
        }
        if (ore != null && ore > 0) {
            userOreSV.transfer(user, account, ore, pinPassword);
        }
        if (active != null && active > 0) {
            activePoolSV.userTransfer(user, account, active, pinPassword);
        }
        return BeanRet.create(true, "成功转账");
    }

    /**
     * 提炼矿石
     */
    @ApiOperation(value = "提炼矿石", notes = "提炼矿石")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "num", value = "提炼数量", paramType = "query", required = true),
            @ApiImplicitParam(name = "pinPassword", value = "交易密码", paramType = "query", required = true),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @PostMapping(value = "/refineOre")
    @ResponseBody
    public BeanRet refineOre(@ApiIgnore HttpServletRequest request, Integer num, String pinPassword) {
        if (num == null || StringUtils.isEmpty(pinPassword)) {
            return BeanRet.create(false, "参数为空");
        }
        String userCode = this.getUserCode(request);
        userOreSV.refineOre(userCode, num, pinPassword);

        return BeanRet.create(true, "提炼转账");
    }


    /**
     * 用户动态复投
     */
    @ApiOperation(value = "用户动态复投", notes = "用户动态复投")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "payType", value = "支付方式", paramType = "query", required = true),
            @ApiImplicitParam(name = "pinPassword", value = "交易密码", paramType = "query", required = true),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @PostMapping("/recast")
    @ResponseBody
    public BeanRet recast(@ApiIgnore HttpServletRequest request, String payType, String pinPassword) {
        if (StringUtils.isBlank(payType) || StringUtils.isBlank(pinPassword)) {
            return BeanRet.create();
        }
        String userCode = this.getUserCode(request);
        userOreSV.recast(userCode, payType, pinPassword);
        return BeanRet.create(true, "复投成功");
    }

    /**
     * 查询转账列表
     */
    @ApiOperation(value = "查询转账列表", notes = "查询转账列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "type", value = "转账类型(1016)： In 转入，Out 转出，如果不传该参数，则查询全部", paramType = "query"),
            @ApiImplicitParam(name = "sortColumns", value = "倒叙：createTime DESC , 正序： createTime ASC", paramType = "query"),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @GetMapping(value = "/listTransferRecord")
    @ResponseBody
    public BeanRet listTransferRecord(@ApiIgnore HttpServletRequest request, TransferType type, String sortColumns, Integer curPage, Integer pageSize) {
        Page<JlbOreLog> page = new Page<>(pageSize, curPage);
        String userCode = this.getUserCode(request);
        sortColumns = "createTime DESC";//
        List<JlbOreLog> jlbOreLogs = jlbOreLogSV.listForUser(userCode, type, page.genRowStart(), page.getPageSize(), sortColumns);
        page.setVoList(jlbOreLogs);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("page", page);
        jsonObject.put("userCode", userCode);
        return BeanRet.create(true, "成功查询转账列表", jsonObject);
    }


    /**
     * 金兰宝产生记录
     *
     * @return 分页对象
     */
    @ApiOperation(value = "金兰宝产生记录", notes = "金兰宝产生记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @GetMapping(value = "/listJlb")
    @ResponseBody
    public BeanRet listJlb(@ApiIgnore HttpServletRequest request, @ApiIgnore UserMinerWorkRecord userMinerWorkRecord, Integer curPage, Integer pageSize) {
        String userCode = this.getUserCode(request);
        Page<UserMinerWorkRecord> page = new Page<>(pageSize, curPage);
        userMinerWorkRecord.setUserCode(userCode);
        List<UserMinerWorkRecord> userMinerWorkRecords = userMinerWorkRecordSV.list(userMinerWorkRecord, page.genRowStart(), page.getPageSize());
        page.setVoList(userMinerWorkRecords);
        return BeanRet.create(true, "查询成功", page);
    }

    /**
     * 激活币记录
     *
     * @return 分页对象
     */
    @ApiOperation(value = "激活币记录", notes = "激活币记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @GetMapping(value = "/listActive")
    @ResponseBody
    public BeanRet listActive(@ApiIgnore HttpServletRequest request, @ApiIgnore ActiveRecord activeRecord, Integer curPage, Integer pageSize) {
        String userCode = this.getUserCode(request);
        Page<ActiveRecord> page = new Page<>(pageSize, curPage);
        activeRecord.setUserCode(userCode);
        List<ActiveRecord> activeRecords = activeRecordSV.list(activeRecord, page.genRowStart(), page.getPageSize());
        page.setVoList(activeRecords);
        return BeanRet.create(true, "查询成功", page);
    }

    /**
     * 矿石产生记录
     *
     * @return 分页对象
     */
    @ApiOperation(value = "矿石产生记录", notes = "矿石产生记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @GetMapping(value = "/listOre")
    @ResponseBody
    public BeanRet list(@ApiIgnore HttpServletRequest request, @ApiIgnore OreRecord oreRecord, Integer curPage, Integer pageSize) {
        String userCode = this.getUserCode(request);
        Page<OreRecord> page = new Page<>(pageSize, curPage);
        oreRecord.setUserCode(userCode);
        List<OreRecord> oreRecords = oreRecordSV.list(oreRecord, page.genRowStart(), page.getPageSize());
        page.setVoList(oreRecords);
        return BeanRet.create(true, "查询成功", page);
    }


    /**
     * 我的团队人数
     */
    @ApiOperation(value = "我的团队人数", notes = "我的团队人数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @GetMapping(value = "/countMyGroup")
    @ResponseBody
    public BeanRet countMyGroup(@ApiIgnore HttpServletRequest request) {
        String userCode = this.getUserCode(request);
        int count = myGroupSV.countGroup(userCode);
        return BeanRet.create(true, "成功统计推广用户数量", count);
    }

    /**
     * 查看团队详情
     */
    @ApiOperation(value = "查看团队详情", notes = "查看团队详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
    })
    @GetMapping(value = "/listMyGroup")
    @ResponseBody
    public BeanRet listMyGroup(@ApiIgnore HttpServletRequest request, String userCode) {
        Page<UserGroup> page = new Page<>();
        if (StringUtils.isEmpty(userCode)) {
            userCode = this.getUserCode(request);
        }
        User user = userSV.loadByCode(userCode);
        if (user == null) {
            return BeanRet.create(false, "请先登录");
        }
        /*if (YNEnum.N == YNEnum.getYN(user.getIsLeader())) {
            return BeanRet.create(false, "您无权限查看团队信息");
        }*/
        List<UserGroup> userGroups = userGroupSV.listMyGroup(userCode);
        Map<String, Object> params = new HashedMap();
        for (UserGroup userGroup : userGroups) {
            params.put("preUserCode", userGroup.getUserCode());
            int count = userGroupSV.count(params);
            if (count > 0) {
                userGroup.setHaveChild(YNEnum.Y.name());
            } else {
                userGroup.setHaveChild(YNEnum.N.name());
            }
        }
        page.setVoList(userGroups);
        return BeanRet.create(true, "查看团队详情", page);
    }

    /**
     * 我的矿机
     */
    @ApiOperation(value = "我的矿机", notes = "我的矿机")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @GetMapping(value = "/getUserMiner")
    @ResponseBody
    public BeanRet getUserMiner(@ApiIgnore HttpServletRequest request) {
        String userCode = this.getUserCode(request);
        UserMiner userMiner = userMinerSV.loadByUserCode(userCode);
        return BeanRet.create(true, "成功查询矿机信息", userMiner);
    }

    /**
     * 收取金兰宝
     */
    @ApiOperation(value = "收取金兰宝", notes = "收取金兰宝")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @PostMapping(value = "/harvest")
    @ResponseBody
    public BeanRet harvest(@ApiIgnore HttpServletRequest request) {
        String userCode = this.getUserCode(request);
        userJlbSV.harvest(userCode);
        return BeanRet.create(true, "金兰宝收取成功");
    }


    /**
     * 绑定子账户
     *
     * @return BeanRet
     */
    @ApiOperation(value = "关联子账户", notes = "关联子账户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "被关联账户", paramType = "query", required = true),
            @ApiImplicitParam(name = "password", value = "被关联账户密码", paramType = "query", required = true),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @PostMapping(value = "/bindAccount")
    @ResponseBody
    public BeanRet bindAccount(@ApiIgnore HttpServletRequest request, String account, String password) {
        String userCode = this.getUserCode(request);
        userSV.bindAccount(userCode, account, password);
        return BeanRet.create(true, "子账户绑定成功");
    }

    /**
     * 我的关联子账户
     */
    @ApiOperation(value = "我的关联子账户", notes = "我的关联子账户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @GetMapping(value = "/subAccountList")
    @ResponseBody
    public BeanRet subAccountList(@ApiIgnore HttpServletRequest request) {
        String userCode = this.getUserCode(request);
        UserSubAccount userSubAccount = new UserSubAccount();
        userSubAccount.setUserCode(userCode);
        List<UserSubAccount> userSubAccounts = subAccountSV.list(userSubAccount, 0, 50);
        return BeanRet.create(true, "关联子账户查询成功", userSubAccounts);
    }


    /**
     * 绑定/修改银行卡
     */
    @ApiOperation(value = "绑定银行卡", notes = "绑定银行卡")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bankName", value = "开户行", paramType = "query", required = true),
            @ApiImplicitParam(name = "bankNumber", value = "卡号", paramType = "query", required = true),
            @ApiImplicitParam(name = "bankMan", value = "开户人", paramType = "query", required = true),
            @ApiImplicitParam(name = "subBank", value = "开户支行", paramType = "query", required = true),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @PostMapping(value = "/bindBank")
    @ResponseBody
    public BeanRet bindBank(@ApiIgnore HttpServletRequest request, String bankName, String bankNumber, String bankMan, String subBank) {
        String userCode = this.getUserCode(request);
        UserBankCard userBankCard = new UserBankCard();
        userBankCard.setBankName(bankName);
        userBankCard.setBankNumber(bankNumber);
        userBankCard.setBankMan(bankMan);
        userBankCard.setSubBank(subBank);
        userBankCard.setUserCode(userCode);
        userBankCardSV.save(userBankCard);
        return BeanRet.create(true, "银行卡绑定成功");
    }

    /**
     * 删除绑定银行卡
     */
    @ApiOperation(value = "删除绑定银行卡", notes = "删除绑定银行卡")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bankNumber", value = "卡号", paramType = "query", required = true),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @DeleteMapping(value = "/deleteBindBank")
    @ResponseBody
    public BeanRet deleteBindBank(@ApiIgnore HttpServletRequest request, String bankNumber) {
        String userCode = this.getUserCode(request);
        userBankCardSV.delete(bankNumber, userCode);
        return BeanRet.create(true, "成功删除绑定银行卡");
    }

    /**
     * 绑定银行卡列表
     */
    @ApiOperation(value = "绑定银行卡列表", notes = "绑定银行卡列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @GetMapping(value = "/listBindBank")
    @ResponseBody
    public BeanRet listBindBank(@ApiIgnore HttpServletRequest request) {
        String userCode = this.getUserCode(request);
        Map<String, Object> params = new HashedMap();
        params.put("userCode", userCode);
        List<UserBankCard> userBankCards = userBankCardSV.list(params);
        return BeanRet.create(true, "绑定银行卡列表", userBankCards);
    }

    /**
     * 查询用户账户信息
     */
    @ApiOperation(value = "查询用户个人信息", notes = "查询用户个人信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @GetMapping(value = "/getUserBalance")
    @ResponseBody
    public BeanRet getUserBalance(@ApiIgnore HttpServletRequest request) {
        String userCode = this.getUserCode(request);
        //查询用户金兰宝和矿石
        User user = userSV.loadByCode(userCode);
        if (user == null) {
            return BeanRet.create();
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("jlb", user.getUserJlb() != null ? user.getUserJlb().getJlb() : 0);
        jsonObject.put("mallTotalJlb", user.getUserJlb() != null ? user.getUserJlb().getMallTotalJlb() : 0);
        jsonObject.put("ore", user.getUserOre() != null ? user.getUserOre().getOre() : 0);
        jsonObject.put("refineTotalOre", user.getUserOre() != null ? user.getUserOre().getRefineTotalOre() : 0);
        //查询用户激活币
        Map<String, Object> params = new HashedMap();
        params.put("userCode", userCode);
        UserActive userActive = userActiveSV.load(params);
        jsonObject.put("actives", userActive != null ? userActive.getActive() : 0);
        //未领取的矿石
        int total = userOreSV.calculateUnclaimedOre(user.getCode());
        jsonObject.put("unclaimed", total);
        return BeanRet.create(true, "余额查询成功", jsonObject);
    }

    /**
     * 根据账户查询账户信息
     */
    @ApiOperation(value = "根据账户查询账户信息", notes = "根据账户查询账户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "account", paramType = "query"),
            @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "query")
    })
    @GetMapping(value = "/getSubAccount")
    @ResponseBody
    public BeanRet getSubAccount(String account) {
        User user = userSV.loadByAccount(account);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("jlb", user.getUserJlb() != null ? user.getUserJlb().getJlb() : 0);
        jsonObject.put("mallTotalJlb", user.getUserJlb() != null ? user.getUserJlb().getMallTotalJlb() : 0);
        jsonObject.put("ore", user.getUserOre() != null ? user.getUserOre().getOre() : 0);
        jsonObject.put("refineTotalOre", user.getUserOre() != null ? user.getUserOre().getRefineTotalOre() : 0);
        //查询用户激活币
        Map<String, Object> params = new HashedMap();
        params.put("userCode", user.getCode());
        UserActive userActive = userActiveSV.load(params);
        jsonObject.put("actives", userActive != null ? userActive.getActive() : 0);
        //未领取的矿石
        int total = userOreSV.calculateUnclaimedOre(user.getCode());
        jsonObject.put("unclaimed", total);
        return BeanRet.create(true, "余额查询成功", jsonObject);
    }


}
